﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LTJ.Common;
using LTJ.Entity;
using LTJ.FrameWork;
using System.Data;

namespace uswinweb.datacontrol
{
    public partial class basedataList : System.Web.UI.UserControl
    {
        public DataTable basedataTab = new DataTable();
        public string strWhere = " 1=1 ";
        public int pagesize = 10;
        public int pageindex = SASRequest.GetInt("currentPage", 1);
        public string action = SASRequest.GetString("action");
        public string parpms = LTJ.Common.Utils.UrlDecode(SASRequest.GetString("parms").Trim());
        public string pageList = "";
        public string orderstr = "";
        public string bcode = SASRequest.GetString("bid");
        public BaseTypeInfo btInfo = new BaseTypeInfo();
        public basedataList()
        {
            btInfo = BaseTypes.GetBaseTypeCode(bcode);
            int recordcount = 0;
            if (action == "search")
            {
                strWhere += " and name like '%" + parpms + "%'";
            }
            if (bcode != "")
            {
                strWhere += " and code='" + bcode + "'";
            }
            if (action == "del")
            {
                int msg = BaseDatas.DelBaseData(parpms);
            }
            recordcount = BaseDatas.GetBaseDataCount(strWhere);
            basedataTab = BaseDatas.GetBaseDataByPage(pageindex, pagesize, strWhere, orderstr);
            pageList = GetPageList(recordcount, pagesize, pageindex);
        }
        public string GetPageList(int recordcount, int pagesize, int currentpage)
        {
            if (SASRequest.GetInt("postnumber", 0) > 0)
            {
                return LTJ.Common.Utils.LuffyPage(recordcount, pagesize, currentpage, "basedataList.ascx", "postnumber=" + SASRequest.GetInt("postnumber", 0), "showdata");
            }
            else
            {
                return LTJ.Common.Utils.LuffyPage(recordcount, pagesize, currentpage, "basedataList.ascx", "bid=" + bcode + "&action=" + action + "&parms=" + parpms + "", "showdata");
            }
        }
        public string GetName(string pcode, string type)
        {
            string msg = "&nbsp;";
            string strWhere = " code='" + type.Trim() + "' and tcode='" + pcode.Trim() + "' ";
            BaseDataInfo binfo = BaseDatas.GetBaseDataByStr(strWhere);
            if (binfo != null)
            {
                msg = binfo.name;
            }
            return msg;
        }
    }
}